package business.impl;

import java.util.ArrayList;
import java.util.Calendar;
import java.util.List;

import org.springframework.beans.factory.annotation.Required;
import org.springframework.transaction.annotation.Transactional;

import vo.User;
import vo.Warn;
import business.WarnService;
import dao.TopicDAO;
import dao.UserDAO;
import dao.WarnDAO;

public class WarnServiceImpl implements WarnService {

	private WarnDAO warnDao;

	public long getTotalCount() {
		return warnDao.findTotalCount();
	}

	public List<Warn> getAllWarns() {
		return warnDao.findAll();
	}

	public List<Warn> getAllWarns(int start, int pageSize) {
		return warnDao.findAll(start, pageSize);
	}

	@Required
	public void setWarnDao(WarnDAO warnDao) {
		this.warnDao = warnDao;
	}

	@Transactional
	public void addWarn(String name) {
		Warn t = new Warn();
		t.setName(String.valueOf(Calendar.getInstance().getTime()));
		warnDao.create(t);
	}

	@Transactional
	public void addWarn(Warn warn) {
		warnDao.create(warn);
	}

	@Transactional
	public Warn getById(long warnId) {
		return warnDao.getById(warnId);
	}

	@Transactional
	public void update(long warnId) {
		warnDao.update(warnId);
	}

	@Transactional
	public void delete(long warnId) {
		// 不是真是的删除
		warnDao.delete(warnId);
	}

	public List<Warn> getWarnsByUserId(long userId) {
		return warnDao.getWarnsByUserId(userId);

	}

	public List<Warn> getWarnsByTopicId(long topicId) {
		return warnDao.getWarnsByTopicId(topicId);

	}

}